﻿(function ($) {

    app.modals.CreateCategoryModal = function () {
        var _categoryService = abp.services.app.category;
        var _$categoryForm = null;

        var _modalManager;
        this.init = function (modalManager) {
            _modalManager = modalManager;
            //取出Form表单
            _$categoryForm = _modalManager.getModal().find('form[name=CategoryForm]');
            };


        this.save = function () {
            //验证不通过返回
            if (!_$categoryForm.valid()) {
                return;
            }
            //序列化参数
            var category = _$categoryForm.serializeFormToObject();


            _modalManager.setBusy(true);
            _categoryService.createCategory(
                category
            ).done(function () {
                abp.notify.info(app.localize('SavedSuccessfully'));
                _modalManager.close();
                abp.event.trigger('app.createCategoryModalSaved');
            }).always(function () {
                _modalManager.setBusy(false);
            });
        };
    };
})(jQuery);